﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aribaccio;
using Aribaccio.Datum;

namespace BDPAutodetect.Simcore
{
    public class StorageMenuManager
    {
        /// <summary>
        /// 配置菜单文件名称
        /// </summary>
        protected const string CONFIG_MENU_NAME = @"Config\Menu.xml";
        /// <summary>
        /// 存储文件实例
        /// </summary>
        protected StorageXmlFile StorageFile { get; set; }
        public MenuData? MenuData { get; protected set; }
        public string Name => StorageFile.Name;
        /// <summary>
        /// 配置设备全路径名称
        /// </summary>
        public string MenuPathName => PathHelper.GetPathFullFileName(CONFIG_MENU_NAME);

        /// <summary>
        /// 构造函数[注入]
        /// </summary>
        public StorageMenuManager()
        {
            this.StorageFile = new StorageXmlFile("菜单存储管理中心");
        }

        /// <summary>
        /// 初始化
        /// </summary>
        public void Initialize()
        {
            var result = this.StorageFile.XMLReadStreamData<MenuData>(this.MenuPathName);
            if (result.ResultState && result.Data != null)
            {
                this.MenuData = result.Data;
            }
        }

        /// <summary>
        /// 获取菜单项集合
        /// </summary>
        /// <returns></returns>
        public List<MenuDataItem> GetMenuItems()
        {
            if (this.MenuData == null || this.MenuData.MenuItems == null) return new List<MenuDataItem>();
            return this.MenuData.MenuItems;
        }
    }
}
